package com.domain.utils.message;

import com.alibaba.fastjson.JSON;
import com.domain.utils.message.chuanglan.ChuangLanSmsUtil;
import com.domain.utils.message.chuanglan.SmsVariableRequest;
import com.domain.utils.message.chuanglan.SmsVariableResponse;

/**
 * @author tianyh
 * @Description:变量短信发送
 */
public class SmsChuangLan {
    public static final String charset = "utf-8";
    // 请登录zz.253.com 获取创蓝API账号(非登录账号,示例:N1234567)
    public static String account = "M0242232";
    // 请登录zz.253.com 获取创蓝API密码(非登录密码)
    public static String pswd = "zJMAGbBa4n2b70";

    /**
     * @param phoneNum
     * @param userName
     * @param type     1 邀请好友  2 发布邀请好友
     * @return
     */
    public static SmsVariableResponse sendMessage(String phoneNum, String userName, String type) {
        try {
            //变量短信发送的URL 请登录zz.253.com 获取完整的URL接口信息
            String smsVariableRequestUrl = "http://smssh1.253.com/msg/variable/json";
            //设置您要发送的内容：其中“【】”中括号为运营商签名符号，多签名内容前置添加提交
            String msg = "";
            if ("1".equals(type)) {
                msg = "【素友】您的好友{$var}邀请您加入身边的熟人互助平台素友App，点击  {$var}  即刻下载，退订回T";
            }
            if ("2".equals(type)) {
                msg = "【素友】您的朋友{$var}在素友中请求你加为好友，赶快点击下载链接  {$var}  帮个忙吧!退订回T";
            }
            //参数组
            String url = "http://t.cn/E50YEnX";
            String params = "" + phoneNum + "," + userName + "," + url + ";";
            //状态报告
            String report = "true";
            SmsVariableRequest smsVariableRequest = new SmsVariableRequest(account, pswd, msg, params, report);
            String requestJson = JSON.toJSONString(smsVariableRequest);
            String response = ChuangLanSmsUtil.sendSmsByPost(smsVariableRequestUrl, requestJson);
            SmsVariableResponse smsVariableResponse = JSON.parseObject(response, SmsVariableResponse.class);
            return smsVariableResponse;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    public static void main(String[] args) {
        sendMessage("18658138066", "大鹏", "1");
    }


}
